<?php
App::import('Vendor','tcpdf/tcpdf');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Ross Moroney');
$pdf->SetTitle('TCPDF using CakePHP');
$pdf->SetSubject('TCPDF using CakePHP');
$pdf->SetKeywords('TCPDF, CakePHP, PDF, example, test, guide');

// set default header data
$gen = 'Generated: ' . date('Y-m-d');
$pdf->SetHeaderData(null, null, 'UO Psychology Department: CONFIDENTIAL - DO NOT EMAIL', 
										$gen);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 

// set font
$pdf->SetFont('times', '', 12);

// add a page
$pdf->AddPage();

ob_start();
?>

<h3> Reference Form for <?php echo $this->data['Application']['firstname'] . ' ' . $this->data['Application']['lastname']; ?></h3>

<h4>Referrer Information</h4>
<p>
	Name: <?php echo $this->data['Reference']['firstname'] . ' '. $this->data['Reference']['lastname']; ?><br />
	Position Title: <?php echo $this->data['Reference']['title']; ?><br />
	Telephone: <?php echo $this->data['Reference']['phone']; ?><br />
	Date Submitted: <?php echo $this->data['Reference']['modified'] ?>
</p>

<dl><dt>Length and Extent of Relationship:</dt>
	<dd><?php echo $this->data['Reference']['knowledge_length'] ?></dd>
</dl>

<p>The Author's School 
	<?php 
		$echstr = '';
	if ($this->data['Reference']['has_grad_prog'] == 0) {
		$echstr = ". The Reference did not respond to whether their school has";
	}
	if ($this->data['Reference']['has_grad_prog'] == 1) {
		$echstr = 'does not have';
	}
	if ($this->data['Reference']['has_grad_prog'] == 2) {
		$echstr = 'does have';
	}
	echo $echstr;
	?> 
	 a graduate program. The author 
	<?php 
		$echstr = '';
	if ($this->data['Reference']['would_admit'] == 0) {
		$echstr = "did not respond to whether they would ";
	}
	if ($this->data['Reference']['would_admit'] == 1) {
		$echstr = 'would not';
	}
	if ($this->data['Reference']['would_admit'] == 2) {
		$echstr = 'would';
	}
	echo $echstr;
	?> 
	  admit the applicant, to their program.

<?php if ($this->data['Reference']['would_admit'] == 1) : ?>
	
<dl><dt>Info Explaining Why the Author Would Not Admit the Applicant:</dt>
	<dd><?php echo $this->data['Reference']['not_admit_info'] ?></dd>
</dl>

<?php endif; ?>

<h4> </h4>

<table>
	<tr><th>Quality Ratings</th><th>Graduate comparisons</th></tr>
	<tr>
		<td>
		<p>
			Intellectual Ability: <?php echo $this->data['Reference']['intel_ability'] ?><br />
			Academic Preparation: <?php echo $this->data['Reference']['academic_prep'] ?><br />
			Maturity/responsibility: <?php echo $this->data['Reference']['maturity'] ?><br />
			Interpersonal skills: <?php echo $this->data['Reference']['interpersonal_skills'] ?><br />
			Oral communication skills: <?php echo $this->data['Reference']['oral_comm'] ?><br />
			Written communication skills: <?php echo $this->data['Reference']['written_comm'] ?><br />
			Ability to complete tasks: <?php echo $this->data['Reference']['finishes_tasks'] ?><br />
			Creative integrative thinking: <?php echo $this->data['Reference']['creative_think'] ?><br />
			Ability to work independently: <?php echo $this->data['Reference']['independent_work'] ?><br />
			Professionally handle clinical issues: <?php echo $this->data['Reference']['professional_clinic'] ?>
    </p>
    </td>
    <td>
    <p>
    	Motivation: <?php echo $this->data['Reference']['motivation'] ?><br />
    	Originality: <?php echo $this->data['Reference']['originality'] ?><br />
    	Initiative: <?php echo $this->data['Reference']['initiative'] ?><br />
			Critical thinking: <?php echo $this->data['Reference']['critical_thinking'] ?><br />
    	Emotional Stability: <?php echo $this->data['Reference']['emot_stability'] ?><br />
  		Perseverance: <?php echo $this->data['Reference']['perseverance'] ?>
		</p>
		</td>
	</tr>
</table>
<h4>Overall Rating: <?php echo $this->data['Reference']['overall'] ?></h4>

<?php
$html = ob_get_contents();	
ob_end_clean();

$pdf->writeHTML($html, true, false, true, false, '');

//Close and output PDF document
$pdf->Output($filename . '.pdf', 'I');
?>